package cmich.cps.scheduler.algorithms;

import cmich.cps.scheduler.data.Course;
import cmich.cps.scheduler.data.Room;

/**
 * The Class KruskalBased.
 * 
 * @author Jonathan Kissinger <kissi1j@cmich.edu>
 */
public class KruskalBased extends Algorithm {
	
	/* (non-Javadoc)
	 * @see cmich.cps.scheduler.algorithms.Algorithm#start()
	 */
	@Override
	public void start() {
		LOGGER.fine("Generating new schedule with Kruskal based algorithm.");
		max = getTheoreticalMax();
		algorithmName = "Kruskal Based";
		seed++;
		generateSchedule();
		if(validator.postValidate(schedule)) {
			bestSchedule = schedule;
		}
	}
	
	/* (non-Javadoc)
	 * @see cmich.cps.scheduler.algorithms.Algorithm#schedulingFail()
	 */
	@Override
	protected void schedulingFailure() {
		String msg = "Error: No available assignments for remaining courses.";
		LOGGER.warning(msg);
		prompts.nonFatalError(msg);
		for(Course course : system.getCourses()) {
			LOGGER.fine("Remaining course: " + course.getName());
		}
		for(Room room : system.getRooms()) {
			if(!room.getLab()) {
				msg = "Remaining timeslots for room: " + room.getName();
				for(String timeslot : room.getTimeslots()) {
					msg = msg + "\n" + timeslot;
				}
				LOGGER.fine(msg);
			}
		}
	}

	/* (non-Javadoc)
	 * @see cmich.cps.scheduler.algorithms.Algorithm#progressBarClosed()
	 */
	@Override
	public void progressBarClosed() {
		if(prompts.confirm("Are you sure you want to cancel the processing of this schedule?")) {
			cancel(true);
		}
	}
}